package iedcyt.acute.view.widgets;

import java.text.Collator;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.TreeMap;

import iedcyt.acute.dataAccess.domain.maesorg.Dbo_REVISTAS_JCR;
import iedcyt.acute.dataAccess.domain.maesorg.JCR_SCI_SSCI;
import iedcyt.acute.dataAccess.domain.maesorg.WoS_REVISTAS_FIs;
import iedcyt.acute.dataAccess.utils.Pair;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;

public class dbo_FITable extends NormalizationTable<Pair<JCR_SCI_SSCI, Dbo_REVISTAS_JCR>> {
	
	public dbo_FITable(Composite composite, int style)
	{
		super(composite, style);
		LABEL = "Revistas dbo con candidatos";
		_label.setText(LABEL);
		
		_table.setHeaderVisible(true);
		
		List <String> fieldColumns=new ArrayList<String>();
		fieldColumns.add("IdJCR");
		fieldColumns.add("Journal JCR");
		fieldColumns.add("Abreviada JCR");
		fieldColumns.add("ISSN");
		fieldColumns.add("Year");
		fieldColumns.add("FI");
		
		for (int loopIndex = 0; loopIndex < fieldColumns.size(); loopIndex++) {
			TableColumn column = new TableColumn(_table, SWT.NULL);
			column.setText(fieldColumns.get(loopIndex));
		}
		addSort();
	}
	
	
	
	private void addSort()
	{
		_table.getColumn(0).addListener(SWT.Selection, new Listener() {
			@Override
			public void handleEvent(Event e) {
				// sort column 0
				TableItem[] items = _table.getItems();
				for (int i = 1; i < items.length; i++) {
					int value1 = Integer.parseInt(items[i].getText(0));
					for (int j = 0; j < i; j++) {
						int value2 = Integer.parseInt(items[j]
								.getText(0));
						if (value1 < value2) {
							TableItem item = new TableItem(_table, SWT.NONE, j);
							item.setText(getItemValues(items[i]));
							items[i].dispose();
							items = _table.getItems();
							break;
						}
					}
				}
			}
		});
		
		
	}

	
	
	@Override
	protected void setItemElement(Pair<JCR_SCI_SSCI, Dbo_REVISTAS_JCR> element, TableItem item) {
		JCR_SCI_SSCI jcr = element.getFirst();
		Dbo_REVISTAS_JCR dbo = element.getSecond();
		
		item.setText(0, dbo.get_IdJCR() + "");
		item.setText(1, dbo.get_JOURNAL_JCR() + "");
		item.setText(2, dbo.get_Abreviada_JCR() + "");
		item.setText(3, dbo.get_ISSN() + "");
		item.setText(4,dbo.get_ANIO_ultimo()+"");
		item.setText(5, jcr.get_IMPACT_FACTOR() + "");
			
		
	}



	
}
